package cc.iotkit.manager.controller.adminMiniApp;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.manager.dto.vo.miniAdmin.MiniAdminDeleteVo;
import cc.iotkit.manager.dto.vo.miniAdmin.MiniAdminGoodsVo;
import cc.iotkit.manager.service.IGoodsService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"后台管理小程序商品管理"})
@Slf4j
@RestController
@RequestMapping("/miniAdmin/goods")
public class MiniAdminGoodsController {

    @Autowired
    private IGoodsService goodsService;

    @Autowired
    private StringRedisTemplate redisTemplate;


    @Autowired
    private ObjectMapper objectMapper;

    @ApiOperation("新增")
    @PostMapping("/add")
    public void add( @RequestBody Request<MiniAdminGoodsVo> goodsReq) throws Exception {
        MiniAdminGoodsVo goodsVo =  goodsReq.getData();
        goodsService.save(goodsVo);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update( @RequestBody Request<MiniAdminGoodsVo> goodsReq) throws Exception {
        MiniAdminGoodsVo goodsVo =  goodsReq.getData();
        goodsService.update(goodsVo);
    }

    @ApiOperation("分页展示")
    @PostMapping("/getPageList")
    public Paging<MiniAdminGoodsVo> getPageList(@RequestBody PageRequest<MiniAdminGoodsVo> request) {
        return goodsService.getPageList(request);
    }

    @ApiOperation("删除")
    @PostMapping(value = "/delete")
    public void delete(@RequestBody MiniAdminDeleteVo vo) {
         goodsService.deleteGoods(vo.getId());
    }
}
